
import { defineStore } from 'pinia'

export const clientStore = defineStore('clientStore', {
  state: () => {
    return {
      client: {
        connected: false,
      }
    }
  }
})

export const tabStore = defineStore('tabStore', {
  state: () => {
    return {
      chatNum: 0,
      settingDot: true,
      targetChatUid: null
    }
  },
  persist: {
    storage: sessionStorage
  }
})

export const userStore = defineStore('userStore', {
  state: () => {
    return {
      uid: null
    }
  },
  persist: {
    storage: sessionStorage
  }
})

export const userListStore = defineStore('userListStore', {
  state: () => {
    return {
      userList: []
    }
  },
  persist: {
    storage: sessionStorage
  }
})

export const friendListStore = defineStore('friendListStore', {
  state: () => {
    return {
      list: []
    }
  },
  persist: {
    storage: sessionStorage
  }
})

export const chatMapStore = defineStore('chatMapStore', {
  state: () => {
    return {
      chatMap: {}
    }
  },
  getters: {
    getChatList: (state) => {
      return (chatUid) => {
        let chatList = state.chatMap[chatUid]
        return chatList ? chatList : []
      }
    }
  },
  actions: {
    addChat(chatUid, data){
      let chatList = this.chatMap[chatUid]
      if(chatList){
        chatList.push(data)
      }else{
        this.chatMap[chatUid] = Array.of(data)
      }
    }
  },
  persist: {
    storage: sessionStorage
  }
})

export const videoStore = defineStore('videoStore', {
  state: () => {
    return {
      videoFlag: false,
      videoUid: null,
      videoRefuse: false,
      called: false,
      videoOk: false,
      videoOffer: null,
      videoAnswer: null,
      videoFromCandidate: null,
      videoToCandidate: null,
    }
  }
})